package eg;

public class code1 {
    public static void main(String[] args) {
       /* //求y=1-1/2+1/3-1/4...-1/100的值
        double result=1;
        double a=1;//忘记要转换类型了,都必须是double类型！
        int num=100;
        for(int i=2;i<=num;i++){
            if(i%2==0){//分母是偶数，减去1/i
                result=result-(a/i);
            }
            else{//分母是奇数，加上1/i
                result=result+(a/i);
            }
        }
        System.out.println("y=1-1/2+1/3-1/4...-1/100="+result);*/
       double y=0;
       double a=1;
        for (int i = 1; i <101 ; i++) {
            if (i%2!=0){
                y=y+(a/i);
            }
            if (i%2==0){
                y=y-(a/i);
            }
        }
        System.out.println("y=1-1/2+1/3-1/4...-1/100="+y);
    }
}
